package com.solomon.travel.common.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.solomon.travel.common.custom.mapper.GuideCustomMapper;
import com.solomon.travel.common.mapper.GuideMapper;
import com.solomon.travel.common.model.Page;
import com.solomon.travel.common.po.Guide;
import com.solomon.travel.common.po.GuideExample;
import com.solomon.travel.common.service.GuideService;

@Service
public class GuideServiceImpl implements GuideService {

	@Override
	public int add(Guide guide) {
		return guideMapper.insertSelective(guide);
	}

	@Override
	public int update(Guide guide) {
		return guideMapper.updateByPrimaryKeySelective(guide);
	}

	@Override
	public Guide getById(String objectId) {
		return guideMapper.selectByPrimaryKey(objectId);
	}

	@Override
	public Guide getByUser(String userId) {
		GuideExample example = new GuideExample();
		example.createCriteria().andUserIdEqualTo(userId);
		List<Guide> guides = guideMapper.selectByExample(example);
		if (!guides.isEmpty()) {
			return guides.get(0);
		}
		return null;
	}
	
	@Resource
	private GuideMapper guideMapper;

	@Override
	public int count() {
		return guideMapper.countByExample(null);
	}

	@Resource
	private GuideCustomMapper guideCustomMapper;
	@Override
	public List<Guide> listGuide(Page page) {
		return guideCustomMapper.listByPage(page);
	}

	@Override
	public Integer countBySerch(Guide guide) {
		return guideCustomMapper.countBySerch(guide);
	}

	@Override
	public List<Guide> listBySerch(Guide guide, Page page) {
		return guideCustomMapper.listBySerch(guide, page);
	}

}
